<template>
  <div>
<!--    头部-->
    <div style="display: flex; height: 60px;line-height: 60px;border-bottom: 1px solid #ccc">
      <div style="width: 200px;text-align: center;display: flex">
       <div> <img src="../../assets/logo.png" alt="" style="width: 40px;position: relative;top:10px;left: 10px"></div>
        <span style="flex: 1">欢迎来到xx系统</span>
      </div>
      <div style="flex: 1">
<!--        导航菜单-->
        <el-menu
            :default-active="'1'"
            class="el-menu-demo"
            mode="horizontal"
            @select="handleSelect"
            background-color="#545c64"
            text-color="#fff"
            active-text-color="#ffd04b" router>
          <el-menu-item index="/front/home">首页</el-menu-item>
          <el-submenu index="2">
            <template slot="title">我的工作台</template>
            <el-menu-item index="/front/item1">高德地图</el-menu-item>
            <el-menu-item index="/front/item2">定位</el-menu-item>
            <el-menu-item index="/front/item3">视频模块</el-menu-item>
            <el-submenu index="2-4">
              <template slot="title">选项4</template>
              <el-menu-item index="2-4-1">选项1</el-menu-item>
              <el-menu-item index="2-4-2">选项2</el-menu-item>
              <el-menu-item index="2-4-3">选项3</el-menu-item>
            </el-submenu>
          </el-submenu>
          <el-menu-item index="/front/article">文章列表</el-menu-item>
          <el-menu-item index="4"><a href="https://www.ele.me" target="_blank">订单管理</a></el-menu-item>
        </el-menu>
      </div>
      <div style="width: 190px">
        <div v-if="!user.username" style="text-align: center">

          <el-button @click="$router.push('/login')" >登录</el-button>
          <el-button @click="$router.push('/register')">注册</el-button>
        </div>
        <div v-else>
          <el-dropdown style="width:150px; cursor:pointer; text-align: right" trigger="click" >
            <div style="display: inline-block;font-size: 15px">
              <img :src="user.avatarUrl" alt=""
                   style="width: 30px;border-radius: 50%; position: relative;top: 10px;right: 5px"/>
              <span>  {{user.username}}</span><i class="el-icon-arrow-down" style="margin-left: 5px"></i>

            </div>
            <el-dropdown-menu slot="dropdown" style="text-align: center">
<!--              <el-dropdown-item style="font-size: 15px;margin: 5px">-->
<!--                <span style="text-decoration: none" @click="person">个人信息</span>-->
<!--              </el-dropdown-item>-->
<!--              <el-dropdown-item style="font-size: 15px;margin: 5px">-->
<!--                <span style="text-decoration: none" @click="modifyPass">修改密码</span>-->
<!--              </el-dropdown-item>-->
              <el-dropdown-item style="font-size: 15px;margin: 5px">
                <span style="text-decoration: none" @click="logout">退出</span>
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div>

      </div>
    </div>



    <div style="width: 90%;margin: 5px auto">
      <router-view/>
    </div>

  </div>
</template>

<script>
import router, {resetRouter} from "@/router";

export default {
  name: "Front",
  data(){
    return{
      user: localStorage.getItem("user")? JSON.parse(localStorage.getItem("user")):{}
    }
  },
  created() {
  },
  methods:{
    handleSelect(key, keyPath) {
      console.log(key, keyPath);
    },
    logout(){
      localStorage.removeItem("user")
      localStorage.removeItem("menus")
      router.push("/login")
      //重置路由
      resetRouter()
      this.$message.success("退出系统成功")
    },
  }
}
</script>

<style scoped>

</style>